#include <iostream>
#include <stdio.h>
#include <map>
using namespace std;
int main() {
	map<string, int> ma;
	ma["rat"]=1;
	ma["ox"]=2;
	ma["tiger"]=3;
	ma["rabbit"]=4;
	ma["dragon"]=5;
	ma["snake"]=6;
	ma["horse"]=7;
	ma["sheep"]=8;
	ma["monkey"]=9;
	ma["rooster"]=10;
	ma["dog"]=11;
	ma["pig"]=12;
	int T;
	cin>>T;
	string a,b;
	int w,h;
	while (T--) {
		cin>>a>>b;
		w=ma[a]; h=ma[b];
		if (w<h) {
			cout<<h-w<<endl; 
		}
		else if (w==h) {
			cout<<12<<endl;
		}
		else {
			cout<<h-w+12<<endl;
		}
	}
	return 0;
} 
